// 游戏对象模块
import { createMario, createPlatform, createEnemy, createCoin, World } from './physics.js';

// 游戏对象
let mario;
let platforms = [];
let enemies = [];
let coins = [];
let score = 0;
let isGameOver = false;

// 创建马里奥
function initMario() {
    mario = createMario(100, 400);
    return mario;
}

// 创建平台和砖块
function createPlatforms() {
    platforms = [];
    
    // 地面
    platforms.push(createPlatform(400, 490, 810, 20));

    // 平台
    platforms.push(createPlatform(300, 380, 150, 20));
    platforms.push(createPlatform(500, 300, 150, 20));
    platforms.push(createPlatform(700, 380, 150, 20));
    platforms.push(createPlatform(200, 380, 150, 20));
    platforms.push(createPlatform(300, 180, 150, 20));

    // 砖块
    platforms.push(createPlatform(540, 200, 50, 50, 'brick'));
    
    return platforms;
}

// 创建敌人
function createEnemies() {
    enemies = [];
    
    enemies.push(createEnemy(480, 450));
    enemies.push(createEnemy(200, 450));
    enemies.push(createEnemy(340, 450));
    
    return enemies;
}

// 创建金币
function createCoins() {
    coins = [];
    
    coins.push(createCoin(220, 340));
    coins.push(createCoin(480, 260));
    coins.push(createCoin(240, 440));
    
    return coins;
}

// 移动敌人
function moveEnemies() {
    enemies.forEach(enemy => {
        // 简单的左右移动
        if (enemy.position.x > 700) {
            enemy.force = { x: -0.002, y: 0 };
        } else if (enemy.position.x < 100) {
            enemy.force = { x: 0.002, y: 0 };
        }
    });
}

// 重置游戏对象
function resetGameObjects() {
    platforms = [];
    enemies = [];
    coins = [];
    score = 0;
    isGameOver = false;
}

function setScore(n){
    score = n;
}
function getScore(){
    return score;
}

export {
    mario,
    platforms,
    enemies,
    coins,
    score,
    setScore,
    getScore,
    isGameOver,
    initMario,
    createPlatforms,
    createEnemies,
    createCoins,
    moveEnemies,
    resetGameObjects
};